package com.dragon.mapper;

import com.dragon.pojo.Record.Record;
import com.dragon.pojo.Record.RecordInfo;
import com.dragon.pojo.Record.RecordList;
import com.dragon.pojo.Record.RecordSelectInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RecordMapper {

    void addRecord(Record record);

    @Delete("DELETE from record where problem_id=#{problemId}")
    void deleteProblemFromRecord(Integer problemId);

    List<RecordList> getRecord(RecordSelectInfo info);

    Integer getRecordTotal(RecordSelectInfo  info);

    @Select("SELECT problem_id, user_id, problem_title, username, avatar, complete_status, score, time, memory, file_size, language, " +
            "code_path, point_list, r.create_time, r.update_time from record r left join online_judge.user u on u.id = r.user_id where r.id=#{recordId}")
    @org.apache.ibatis.annotations.Results({
            @org.apache.ibatis.annotations.Result(property = "pointList", column = "point_list", typeHandler = com.dragon.Handler.custom.JudgeInfoListTypeHandler.class)
    })
    RecordInfo getRecordInfo(Integer recordId);
}
